﻿using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using Newtonsoft.Json;

class Employee
{
    private string[] employeeInfo;
    
    public int EmployeeID;
    public string EmployeeName;
    public string[] EmployeeInfo
    {
        get { return this.employeeInfo; }
        set { this.employeeInfo = value;}
    }
}

/// <summary>
/// WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {

    public WebService () {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string ToJSONString(int employeeID, string employeeName, string[] employeeInfo) 
    {
        Employee employee = new Employee();
        employee.EmployeeID = employeeID;
        employee.EmployeeName = employeeName;
        employee.EmployeeInfo = employeeInfo;

        return JavaScriptConvert.SerializeObject(employee);
    }

    [WebMethod]
    public string ToStrEmployee(string strJSON)
    {
        Employee decerializedEmployee = (Employee)JavaScriptConvert.DeserializeObject(strJSON, typeof(Employee));
        return "ID: " + decerializedEmployee.EmployeeID + "\n"
            + "Name: " + decerializedEmployee.EmployeeName + "\n"
            + "Info: " + decerializedEmployee.EmployeeInfo.ToString();
    }
    
}

